﻿using System;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Mars.GpuInstance
{
    public delegate T LoadAsset<T>(string path);

    public class InstanceResourceManager : IDisposable
    {
        private static InstanceResourceManager instance;

        public static InstanceResourceManager GetInstance()
        {
#if UNITY_EDITOR
            if (instance == null)
#else
            if (instance is null)
#endif
            {
                instance = new InstanceResourceManager();
            }

            return instance;
        }
        
        public LoadAsset<InstanceGenConfig> loadInstanceGenConfigFunc;
        
        

        private InstanceResourceManager()
        {
        }
        
        public InstanceGenConfig LoadInstanceGenConfig(string path)
        {
            InstanceGenConfig config = null;
            if (loadInstanceGenConfigFunc != null)
            {
                config = loadInstanceGenConfigFunc(path);
            }

#if UNITY_EDITOR
            else
            {
                config = AssetDatabase.LoadAssetAtPath<InstanceGenConfig>(path);
            }
#endif
            return config;
        }
        
        public void Dispose()
        {
            Clear();
        }

        public void Clear()
        {
        }
    }
}